package oct2013.linkednode;

public class ConvertSortedArraytoBinarySearchTree {
	public TreeNode sortedArrayToBST(int[] num) {
		return sort(num, 0, num.length - 1);
	}

	TreeNode sort(int[] num, int l, int r) {
		if (l > r)
			return null;
		int m = l + r >> 1;
		TreeNode root = new TreeNode(num[m]);
		root.left = sort(num, l, m - 1);
		root.right = sort(num, m + 1, r);
		return root;
	}
}
